package screen.item;

import globals.Global;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;

/**
 * @author Ben Elliott
 *
 */
public abstract class TextButton extends InteractableItem {
	private String text;
	private Font font;
	
	
	public Color color, mouseOverColor;
	
	public TextButton(String text) {
		this.text = text;	
	}
	
	public TextButton(String text, int x, int y, Color color, Font font, FontMetrics fontMetrics) {
		this.text = text;
		this.font = font;
		this.color = color;
		this.mouseOverColor = color;
		this.x = x;
		this.y = y;
		
		width = fontMetrics.stringWidth(text);
		height = fontMetrics.getHeight();
	}
	
	public void Update(float elapsed) {
		// Check for MouseOver
		if (Global.Instance().input.mouseX > x &&
			Global.Instance().input.mouseX < x+width &&
			Global.Instance().input.mouseY > y &&
			Global.Instance().input.mouseY < y+height) {
			mouseOver = true;
			
			// Check for mouse click
			if (Global.Instance().input.isMouseClicked()) mouseClick();
		} else {
			mouseOver = false;
		}
	}
	public void Draw(Graphics graphics) {
		// Set up button attributes
		graphics.setFont(font);
		
		if (mouseOver) {
			mouseOver();
			graphics.setColor(mouseOverColor);
		} else {
			graphics.setColor(color);
		}

		graphics.drawString(text, x, y+height);
	}
	
	public abstract void mouseOver();
}
